//
//  QLBxOrderCostVC.m
//  Xiaomakuaixiu
//
//  Created by 龚碧容 on 2017/10/23.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "QLBxOrderCostVC.h"

#import "QLBxOrderCostMidCell.h"
#import "QLBxOrderCostBotCell.h"

#import "QLMPayMoneyVC.h"
#import "QLMCostListModel.h"

//#import "AppDelegate.h"

@interface QLBxOrderCostVC ()<UITableViewDataSource,UITableViewDelegate>{
    
    NSArray *titleArr;
    NSArray *value12Arr;

    NSString *totalFirstStr;
    NSString *totalSecondStr;
    NSString *lastPrice;
    
    QLMCostListModel *costListModel;
    QLMOrderListInfoModel *_resultInfoModel;
}

@property (nonatomic,strong) UITableView *costtableview;
@property (nonatomic,strong) UIView *topBackView;
@property (nonatomic,strong) UILabel *totalTipLabel;
@property (nonatomic,strong) UIButton *paymoneyButton;

@property (nonatomic,strong) UILabel *haspaidLabel;
@property (nonatomic,strong) UILabel *hasSerpaidLabel;

@property (nonatomic,strong) NSLayoutConstraint *tabConstraint;

@end

@implementation QLBxOrderCostVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title=@"订单费用详情";
    costListModel.partList=[NSArray array];
    costListModel.partAll=[NSArray array];
    costListModel.en=[NSDictionary dictionary];
    
    value12Arr=[NSArray arrayWithObjects:@"里程费",@"工时费",@"服务费",nil];
    titleArr=[NSArray arrayWithObjects:@"配件费",@"服务费",@"综合",nil];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //横屏
//    AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    delegate.allowRotate = 1;
    
    [self requRepairOrder];
    [self requestCostData];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    //横屏
//    AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
//    delegate.allowRotate = 0;
//
//    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
//        SEL selector = NSSelectorFromString(@"setOrientation:");
//        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
//        [invocation setSelector:selector];
//        [invocation setTarget:[UIDevice currentDevice]];
//        int val = UIInterfaceOrientationPortrait;
//        [invocation setArgument:&val atIndex:2];
//        [invocation invoke];
//    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -
- (void)loadView{
    self.view = [UIView new];
    [self.view addSubview:self.costtableview];
    [self.view addSubview:self.topBackView];
    [self.topBackView addSubview:self.paymoneyButton];
}

- (void)requRepairOrder{
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:_orderListInfoModel.repairOrderId forKey:@"repairOrderId"];
    
    [ClientTool postUrlPath:@"/test/repairOrder/orderInfo" withParamers:paramerDic andBody:nil
                    success:^(id responseObject){
                        
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            _resultInfoModel=[[QLMOrderListInfoModel alloc] initWithDictionary:responseObject[@"repairOrder"] error:nil];
                            
                            if (_isBXPayMoneyJumpBool) {
                                ETToastWithDelay(@"订单支付成功，您可以返回到报修详情界面点击去评价对此订单进行评价",3);
                            }
                            
                            [self _updateMainUI];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        ETToast(@"服务器连接失败");
                    }
     ];
}

#pragma mark - 横屏刷新界面
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    // do something before rotation
    [_costtableview reloadData];
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    // do something after rotation
}

- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString{
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err){
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

#pragma mark -
- (void)requestCostData{
    NSMutableDictionary *paramerDic=[NSMutableDictionary dictionary];
    [paramerDic setObject:_orderListInfoModel.erpOrderNo forKey:@"borrowId"];
    
    [self.view makeToastActivity:CSToastPositionCenter];
    [ClientTool postUrlPath:@"/rest/servPartSales/getservPartSalesByBorrowId"
               withParamers:paramerDic
                    andBody:nil
                    success:^(id responseObject){
                        [self.view hideToastActivity];
                        NSInteger code = [[responseObject objectForKey:@"flag"] integerValue];
                        if (code == 1) {
                            
                            costListModel=[[QLMCostListModel alloc] init];
                            costListModel.partList=[responseObject[@"list"] objectForKey:@"partList"];
                            costListModel.partAll=[responseObject[@"list"] objectForKey:@"partAll"];
                            costListModel.en=[responseObject[@"list"] objectForKey:@"en"];
                            
                            [_costtableview reloadData];
                        }else{
                            ETToast(responseObject[@"msg"]);
                        }
                    }failure:^(NSError *error){
                        [self.view hideToastActivity];
                        ETToast(@"服务器连接失败");
                    }
     ];
}

- (void)payMoneyAction:(UIButton *)btn{
    QLMPayMoneyVC *payMoneyVC=[QLMPayMoneyVC new];
    payMoneyVC.orderListInfoModel=_orderListInfoModel;
    payMoneyVC.moneyStr=[NSString stringWithFormat:@"%.2f",[lastPrice floatValue]];
    [self.navigationController pushViewController:payMoneyVC animated:YES];
}

- (UITableView *)costtableview{
    if (!_costtableview) {
        _costtableview=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, kScreen_height-QLM_StatusBarAndNavigationBarHeight-44-IOS11_OR_LATER_SPACE(34)) style:UITableViewStylePlain];
        _costtableview.backgroundColor=[UIColor clearColor];
        _costtableview.delegate=self;
        _costtableview.dataSource=self;
        _costtableview.separatorStyle=UITableViewCellSeparatorStyleNone;
        _costtableview.showsVerticalScrollIndicator=NO;
        _costtableview.showsHorizontalScrollIndicator=NO;
        _costtableview.tableFooterView=[UIView new];
    }
    return _costtableview;
}

- (UIView *)topBackView{
    if (!_topBackView) {
        _topBackView=[[UIView alloc] initWithFrame:CGRectMake(0, kScreen_height-QLM_StatusBarAndNavigationBarHeight-44-IOS11_OR_LATER_SPACE(34), kScreen_width, 44+IOS11_OR_LATER_SPACE(34))];
        _topBackView.backgroundColor=[UIColor whiteColor];
        _topBackView.userInteractionEnabled=YES;
    }
    return _topBackView;
}

- (UIButton *)paymoneyButton{
    if (!_paymoneyButton) {
        _paymoneyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _paymoneyButton.frame=CGRectMake(0, 0, kScreen_width, 44);
        [_paymoneyButton setTitle:@"去支付" forState:UIControlStateNormal];
        [_paymoneyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _paymoneyButton.backgroundColor = kButtonColor;
        [_paymoneyButton addTarget:self action:@selector(payMoneyAction:) forControlEvents:UIControlEventTouchUpInside];
        _paymoneyButton.titleLabel.font=[UIFont systemFontOfSize:16.0f];
    }
    return _paymoneyButton;
}

- (void)_updateMainUI{
    if ([_resultInfoModel.erpOrderStatus integerValue]!=2&&[_resultInfoModel.erpOrderStatus integerValue]!=-1){
        [_costtableview setFrame:CGRectMake(0, 0, kScreen_width, kScreen_height-QLM_StatusBarAndNavigationBarHeight-44-IOS11_OR_LATER_SPACE(34))];
        
        if ([_resultInfoModel.erpOrderStatus integerValue]==1) {
            _topBackView.hidden=YES;
        }else{
            _topBackView.hidden=NO;
        }
    }else{
        _topBackView.hidden=YES;
        [_costtableview setFrame:CGRectMake(0, 0, kScreen_width, kScreen_height-QLM_StatusBarAndNavigationBarHeight-IOS11_OR_LATER_SPACE(34))];
    }
}

- (void)_updateTotalTipLabel{
    
    QLMCostEnModel *costEnModel=[[QLMCostEnModel alloc] initWithDictionary:costListModel.en error:nil];
    if ([ClientTool isNull:costEnModel.hasPaid]) {
        NSString *hasStr=[NSString stringWithFormat:@"已付配件款:￥%@",costEnModel.hasPaid];
        NSMutableAttributedString *hasString=[[NSMutableAttributedString alloc] initWithString:hasStr];
        [hasString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(6, hasStr.length-6)];
        _haspaidLabel.attributedText=hasString;
    }
    
    if ([ClientTool isNull:costEnModel.servHaspaid]) {
        NSString *hasStr=[NSString stringWithFormat:@"已付服务款:￥%@",costEnModel.servHaspaid];
        NSMutableAttributedString *hasString=[[NSMutableAttributedString alloc] initWithString:hasStr];
        [hasString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(6, hasStr.length-6)];
        _hasSerpaidLabel.attributedText=hasString;
    }
    
    lastPrice=[NSString stringWithFormat:@"%.2f",[totalFirstStr floatValue]+[totalSecondStr floatValue]-[costEnModel.hasPaid floatValue]-[costEnModel.servHaspaid floatValue]];
    if([_resultInfoModel.erpOrderStatus integerValue]==2){
        lastPrice=[NSString stringWithFormat:@"%.2f",[totalFirstStr floatValue]+[totalSecondStr floatValue]];
    }
    NSString *telStr=[NSString stringWithFormat:@"总计:￥%@",lastPrice];
    NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:telStr];
    [aString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(3, telStr.length-3)];
    _totalTipLabel.attributedText=aString;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (BOOL)isNull:(id)object{
    // 判断是否为空串
    if ([object isEqual:[NSNull null]]) {
        return NO;
    }else if ([object isKindOfClass:[NSNull class]]){
        return NO;
    }else if (object==nil){
        return NO;
    }else if ([object isEqualToString:@"0.0"]){
        return NO;
    }
    return YES;
}

#pragma mark - UITableView datasource
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 34;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView=[[UIView alloc] init];
    headerView.backgroundColor=[UIColor whiteColor];
    
    UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom];
    newButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    newButton.frame = CGRectMake(15, 5, 160, 24);
    [newButton setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
    [newButton setTitle:titleArr[section] forState:UIControlStateNormal];
    [newButton setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
    newButton.titleLabel.font=[UIFont systemFontOfSize:16.0f];
    newButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    newButton.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    [headerView addSubview:newButton];
    
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 33.5, kScreen_width, 0.5)];
    lineView.backgroundColor=[UIColor lightGrayColor];
    [headerView addSubview:lineView];
    
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section==0) {
        return 58;
    }else if (section==1) {
        return 58;
    }
    return 0.1;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView=[[UIView alloc] init];
    footerView.backgroundColor=UIColorFromRGB(0xf5f5f5);
    footerView.userInteractionEnabled=YES;
    if (section!=2) {
        
        UIView *topBackView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_width, 48)];
        topBackView.backgroundColor=[UIColor whiteColor];
        [footerView addSubview:topBackView];
 
        NSString *totalStr=@"0.0";
        NSString *zhekouStr=nil;
        if (costListModel.partAll.count!=0) {
            QLMCostAllModel *costAllModel=[[QLMCostAllModel alloc] initWithDictionary:costListModel.partAll[0] error:nil];
            if (section==1) {
                totalStr = [NSString stringWithFormat:@"%.1f",[costAllModel.mileage floatValue]*3+[costAllModel.time floatValue]*100];
               totalSecondStr =totalStr;
            }else{
             
                zhekouStr=[NSString stringWithFormat:@"%.1f",[costAllModel.zhekouMoney floatValue]];
                NSMutableArray *numtotalArr=[NSMutableArray array];
                for ( int i=0;i<costListModel.partList.count;i++) {
                    QLMCostModel *costModel=[[QLMCostModel alloc] initWithDictionary:costListModel.partList[i] error:nil];
                    NSString *priceStr = [NSString stringWithFormat:@"%.1f",[costModel.salePrice floatValue]*[costModel.outQty floatValue]];
                    [numtotalArr addObject:priceStr];
                }
                totalStr = (NSString *)[numtotalArr valueForKeyPath:@"@sum.floatValue"];
                
                if (costAllModel.zhekouMoney.length!=0) {
                    totalFirstStr=zhekouStr;
                }else{
                    totalFirstStr=totalStr;
                }
                
            }
        }
    
        NSString *telStr=[NSString stringWithFormat:@"小计：￥%.1f",[totalStr floatValue]];
        NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:telStr];
        [aString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(3, aString.length-3)];
    
        UILabel *addreTipLabel=[[UILabel alloc] initWithFrame:CGRectMake(15, 9, 140, 30)];
        addreTipLabel.font=[UIFont systemFontOfSize:16];
        addreTipLabel.textColor=UIColorFromRGB(0x333333);
        addreTipLabel.attributedText=aString;
        addreTipLabel.textAlignment=NSTextAlignmentLeft;
        [topBackView addSubview:addreTipLabel];
        if (section==0) {
            if ([self isNull:zhekouStr]) {
                NSString *desStr=[NSString stringWithFormat:@"折后：￥%@",zhekouStr];
                NSMutableAttributedString *zheString=[[NSMutableAttributedString alloc] initWithString:desStr];
                [zheString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(3, zheString.length-3)];
                
                UILabel *zheTipLabel=[[UILabel alloc] initWithFrame:CGRectMake(165, 9, 140, 30)];
                zheTipLabel.font=[UIFont systemFontOfSize:16];
                zheTipLabel.textColor=UIColorFromRGB(0x333333);
                zheTipLabel.attributedText=zheString;
                zheTipLabel.textAlignment=NSTextAlignmentLeft;
                [topBackView addSubview:zheTipLabel];
            }
        }
    }
    return footerView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section==0){
        return costListModel.partList.count+1;
    }else if (section==1){
        if (costListModel.partAll.count==0) {
            return 1;
        }
        return 2+1;
    }
    return 3;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==2) {
        return 30;
    }
    return 44;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0){
        QLBxOrderCostMidCell *cell=[QLBxOrderCostMidCell cellWithTableView:tableView];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0,43.5,kScreen_width,0.5)];
        lineView.backgroundColor=[UIColor lightGrayColor];
        [cell addSubview:lineView];
        
        if (indexPath.row!=0) {
            
            QLMCostModel *costModel=[[QLMCostModel alloc] initWithDictionary:costListModel.partList[indexPath.row-1] error:nil];
            
            cell.peijianIdLabel.textColor=UIColorFromRGB(0xf3ca20);
            cell.peijianIdLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
            
            cell.serialNoLabel.text=costModel.partNo;
            cell.peijianNameLabel.text=costModel.partName;
            cell.peijianNumLabel.text=costModel.outQty;
            cell.vipPriceLabel.text=[NSString stringWithFormat:@"%.2f",[costModel.partZhekoulv floatValue]];

            if (costModel.salePrice.length==0) {
                cell.peijianPriceLabel.text=@"0.0";
            }else{
                cell.peijianPriceLabel.text=[NSString stringWithFormat:@"%.1f",[costModel.salePrice floatValue]];
            }
            
        }else{
            cell.serialNoLabel.text=@"品号";
            cell.peijianNameLabel.text=@"品名";
            cell.peijianNumLabel.text=@"数量";
            cell.peijianPriceLabel.text=@"单价";
            cell.vipPriceLabel.text=@"会员折扣率";
        }

        if (indexPath.row==0) {
            cell.backgroundColor=UIColorFromRGB(0xf9f9f9);
        }else{
            cell.backgroundColor=[UIColor whiteColor];
        }
        return cell;
    }else if (indexPath.section==1){
    
        QLBxOrderCostBotCell *cell=[QLBxOrderCostBotCell cellWithTableView:tableView];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        
        UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0,43.5,kScreen_width,0.5)];
        lineView.backgroundColor=[UIColor lightGrayColor];
        [cell addSubview:lineView];

        if (indexPath.row!=0) {
            cell.costidLabel.textColor=UIColorFromRGB(0xf3ca20);
            cell.costidLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
            cell.costNameLabel.text=value12Arr[indexPath.row-1];
            
            if (costListModel.partAll.count!=0) {
                QLMCostAllModel *costAllModel=[[QLMCostAllModel alloc] initWithDictionary:costListModel.partAll[0] error:nil];
                if (indexPath.row==1) {
                    cell.extraPriceLabel.text=[NSString stringWithFormat:@"%@",costAllModel.mileage];
                    cell.costNumLabel.text=[NSString stringWithFormat:@"x3"];
                    cell.costPriceLabel.text=[NSString stringWithFormat:@"%.1f",[costAllModel.mileage floatValue]*3];
                }else if (indexPath.row==2){
                    cell.extraPriceLabel.text=[NSString stringWithFormat:@"%@",costAllModel.time];
                    cell.costNumLabel.text=[NSString stringWithFormat:@"x100"];
                    cell.costPriceLabel.text=[NSString stringWithFormat:@"%.1f",[costAllModel.time floatValue]*100];
                }
            }
            
        }else{
            cell.costNameLabel.text=@"项目";
            cell.costNumLabel.text=@"数量";
            cell.costPriceLabel.text=@"金额";
            cell.costNumLabel.textColor=[UIColor darkGrayColor];
            [cell.costNumLabel setFrame:CGRectMake(kScreen_width/2-60, 5, kScreen_width/2-60+30, 34)];
        }
        
        if (indexPath.row==0) {
            cell.backgroundColor=UIColorFromRGB(0xf9f9f9);
        }else{
            cell.backgroundColor=[UIColor whiteColor];
        }
        
        return cell;
    }
    
    static NSString *cellId=@"";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    
    cell.textLabel.font=[UIFont systemFontOfSize:15];
    cell.textLabel.textColor=[UIColor darkGrayColor];
    cell.textLabel.backgroundColor=[UIColor whiteColor];
    cell.textLabel.textAlignment=NSTextAlignmentLeft;
    
    QLMCostEnModel *costEnModel=[[QLMCostEnModel alloc] initWithDictionary:costListModel.en error:nil];
    if (indexPath.row==0) {
        if ([ClientTool isNull:costEnModel.hasPaid]) {
            NSString *hasStr=[NSString stringWithFormat:@"已付配件款:￥%@",costEnModel.hasPaid];
            NSMutableAttributedString *hasString=[[NSMutableAttributedString alloc] initWithString:hasStr];
            [hasString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(6, hasStr.length-6)];
            cell.textLabel.attributedText=hasString;
        }
    }else if (indexPath.row==1) {
        if ([ClientTool isNull:costEnModel.servHaspaid]) {
            NSString *hasStr=[NSString stringWithFormat:@"已付服务款:￥%@",costEnModel.servHaspaid];
            NSMutableAttributedString *hasString=[[NSMutableAttributedString alloc] initWithString:hasStr];
            [hasString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(6, hasStr.length-6)];
            cell.textLabel.attributedText=hasString;
        }
    }else{
        lastPrice=[NSString stringWithFormat:@"%.2f",[costEnModel.totalMoney floatValue]-[costEnModel.hasPaid floatValue]-[costEnModel.servHaspaid floatValue]];
        if([_resultInfoModel.erpOrderStatus integerValue]==2){
            lastPrice=[NSString stringWithFormat:@"%.2f",[costEnModel.totalMoney floatValue]];
        }
        NSString *telStr=[NSString stringWithFormat:@"总计:￥%@",lastPrice];
        NSMutableAttributedString *aString=[[NSMutableAttributedString alloc] initWithString:telStr];
        [aString addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xf93939) range:NSMakeRange(3, telStr.length-3)];
        cell.textLabel.attributedText=aString;
    }
    
    return cell;
}

#pragma mark - 设置cell分割线做对齐
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

-(void)viewDidLayoutSubviews {
    
    if ([_costtableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [_costtableview setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([_costtableview respondsToSelector:@selector(setLayoutMargins:)])  {
        [_costtableview setLayoutMargins:UIEdgeInsetsZero];
    }
}

#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
